import React, { forwardRef, useEffect, useImperativeHandle, useState } from 'react';
import APIlist from './apilist'
import {
    Button,
    DatePicker,
    Form,
    Input,
    Modal,
    Radio,
    Tag,
    Select,
    InputNumber,
    message,
    Row,
    Col,
} from 'antd';
import { modalLayoutLg, modalLayoutSm } from '@/config/layout';
import { request } from 'umi';
const DictModal = (props: any, refs: any) => {
    const [form] = Form.useForm();
    // const [fileList,setfileList] = useState([]);
    const [measureClassData, setmeasureClassData] = useState([]);
    const { setFieldsValue, resetFields } = form;
    const [index, setindex] = useState(0);
    const [code, setCode] = useState('');
    const [isModalVisible, setIsModalVisible] = useState(false);
    const { TextArea } = Input;
    //显示弹窗
    const showModal = () => {
        setIsModalVisible(true);
    };

    //取消
    const handleCancel = () => {
        setIsModalVisible(false);
        setCode('');
        resetFields();
    };
    //确定
    const handleOk = (data) => {
        console.log(data);
        props.sure && props.sure(data, index);
        handleCancel();
    };

    useImperativeHandle(refs, () => ({
        init: (index) => {
            // setfileList([]);
            setindex(index);
            showModal();
        },
    }));

    return (
        <Modal
            title={'选择api'}
            visible={isModalVisible}
            onOk={handleOk}
            onCancel={handleCancel}
            centered
            width={1000}
            destroyOnClose
            maskClosable={false}
            bodyStyle={{
                maxHeight: window.innerHeight - 150,
                overflowY: 'auto',
            }}
            footer={<Button onClick={handleCancel}>关闭</Button>}
        >
            <APIlist onOk={handleOk} />
        </Modal>
    );
};
const AddMCom = forwardRef(DictModal);
export default AddMCom;
